import 'dart:ui';

import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/ui/route/helper/route_helper.dart';
import 'package:app/src/utils/image_path_utils.dart';

import '../../../http/bean/clockin/attendances.dart';
import '../../../http/bean/clockin/clock_in.dart';
import '../../../http/bean/clockin/clockin_point_range.dart';
import '../../../http/model/clokin_model.dart';
import '../../../manager/user_manager.dart';
import '../../dialog/dailog.dart';
import 'clock_in_result.dart';
import 'clock_in_ui.dart';

///打卡签到结果页面：强制性工单签退，提示页面。
class ClockinResultGongdanRoute extends StatefulWidget {
  //{"MsgCode":"100","MsgDetail":"签到成功，请联系班长进行确认！","Data":true}
  //这个字段显示服务器打卡签到成功的信息。
  static String? MsgDetail = "";
  static bool isOffWork = false; //是否为下班打卡签到。
  static bool is102 = true; // 102 当日结算 103本次结算

  @override
  _State createState() => _State();
}

var _dispose = false;

class _State extends State<ClockinResultGongdanRoute> {
  _Presenter presenter = _Presenter();

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _dispose = true;
  }

  @override
  void initState() {
    super.initState();
    _dispose = false;
    presenter?.setState = setState;
  }

  @override
  Widget build(BuildContext context) {
    px.init(context);
    var scaffold = Scaffold(
      backgroundColor: AppColors.backgroundColorWithWhite,
      appBar: AppBar(
        backgroundColor: AppColors.backgroundColorWithWhite,
        elevation: 0,
        leading: AppUi.getBack(context, () {
          return false;
        }, color: Colors.black),
        centerTitle: true,
        leadingWidth: 36,
        titleSpacing: 0,
        //打卡结果
        title: Text(
          AppStrings.of(context).ClockInResult,
          style: AppStyle.textStyleWithTitle(),
        ),
      ),
      body: Material(
          color: AppColors.backgroundColorWithWhite, child: _body(context)),
      bottomNavigationBar: _bottom(context),
    );
    return WillPopScope(
      child: scaffold,
      onWillPop: () async {
        return true;
      },
    );
  }

  Widget _body(BuildContext context) {
    return Scrollbar(
      child: SingleChildScrollView(
        physics: BouncingScrollPhysics(),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            _clockSuccess(context),
            //强制性工单（标题）
            ClockInUi.tableGondanTitle(context, presenter?.clokinData,
                presenter?.wageSettlement, ClockinResultRoute.is102),
            ///强制性工单列表
            ClockInUi.tableGondan(context, presenter?.clokinData,
                presenter?.wageSettlement, ClockinResultRoute.is102),
          ],
        ),
      ),
    );
  }

  ///打卡成功
  Widget _clockSuccess(BuildContext context) {
    // String? content = ClockinResultRoute.MsgDetail;
    String? content ="有2个强制性工单未完成，无法签退";
    if (StringUtils.isEmpty(content)) {
      content = AppStrings.of(context).clockInSuccess; //打卡成功
    }
    return Container(
      child: Text(
        "$content" ?? "",
        textAlign: TextAlign.center,
        style: TextStyle(
            color: ColorUtils.parseColor("#3C89F1"),
            fontSize: px.x(100),
            fontWeight: FontWeight.bold),
      ),
      color: AppColors.backgroundColorWithWhite,
      alignment: Alignment.center,
      width: px.screenWidth(),
      //height: px.y(300),
    );
  }

  ///底部布局
  Widget _bottom(BuildContext context) {
    List<Widget> children = [];
    var _fontSize = px.x(50);
    var _textColor = Colors.black;
    //查看打卡记录
    // Text text = Text(
    //   AppStrings.of(context).checkClock,
    //   style: TextStyle(color: _textColor, fontSize: _fontSize),
    // );
    // var container = Container(
    //   child: InkWell(
    //     child: text,
    //     onTap: () {
    //       //打卡记录
    //       AppRouteHelper.goClockinRecordRoute(context, isReplacement: true);
    //     },
    //   ),
    //   alignment: Alignment.center,
    //   margin: EdgeInsets.only(top: 5, bottom: 5, left: 0, right: 10),
    //   width: px.x(400),
    //   height: px.x(160),
    // );
    // children.add(container);
    //我知道了
    Text text2 = Text(
      AppStrings.of(context).iknow,
      style: TextStyle(color: _textColor, fontSize: _fontSize),
    );
    var container2 = Container(
      child: InkWell(
        child: text2,
        onTap: () {
          AppRouteHelper.pop(context);
        },
      ),
      alignment: Alignment.center,
      width: px.x(400),
      height: px.x(160),
      margin: EdgeInsets.only(top: 5, bottom: 5, left: 10, right: 0),
    );
    children.add(container2);
    var row = Row(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: children,
    );
    return Container(
      child: row,
      height: px.x(160),
      alignment: Alignment.bottomCenter,
      margin: EdgeInsets.only(top: 0),
    );
  }
}

class _Presenter {
  StateSetter? setState = null;
  ClokinPointRange? clokinData = null;
  WageSettlement? wageSettlement = null; //工资结算
  //服务器签到班組
  MyGroupBcInfo? GroupBcInfo = null;

  //服务器签到班次
  MyAttendances? attendances = null;

  ///判断是否为上班打卡成功；true 上班打卡成功；false 下班打卡成功。
  bool isOnWork() {
    return clokinData?.isOnWork() ?? false;
  }
}
